package logic

import (
	"context"
	"house/model/mysql"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *house.HouseListRequest) (*house.HouseListResponse, error) {
	// todo: add your logic here and delete this line

	var u mysql.User
	var s []mysql.Shop
	u.ID = uint(in.UserId)

	mysql.DB.Limit(1).Find(&u)

	mysql.DB.Find(&s)
	var houserList []*house.HouseList

	for _, d := range s {
		if d.UserId == int(in.UserId) {
			houserList = append(houserList, &house.HouseList{
				Mobile:   u.Mobile,
				Password: u.Password,
				Title:    d.Title,
				Info:     d.Info,
				Price:    float32(d.Price),
				Num:      d.Num,
				Image:    d.Image,
				UserId:   int64(d.UserId),
			})
		}

	}
	return &house.HouseListResponse{

		List: houserList,
	}, nil
}
